package org.example.controller;

import io.swagger.annotations.ApiOperation;
import org.example.annotation.Log;
import org.example.domain.dto.PageDTO;
import org.example.domain.po.ErpUser;
import org.example.domain.vo.ErpMenuBtnVO;
import org.example.domain.vo.ErpRoleMenuVO;
import org.example.enums.BusinessType;
import org.example.service.ErpRoleMenuService;
import org.example.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RequestMapping("roleMenu")
@RestController
public class ErpRoleMenuController {
    
    @Resource
    private ErpRoleMenuService roleMenuService;
    
    @GetMapping("roleBtnStrById")
    @ApiOperation("返回角色按钮权限")
    public Result<List<ErpMenuBtnVO>> roleBtnStrById(Long id) {
        List<ErpMenuBtnVO> roleMenuVOS = roleMenuService.rolePushBtnById(id);
        return Result.success(roleMenuVOS);
    }
    
    @GetMapping("getRoleMenuBtnStr")
    @ApiOperation("返回角色按钮权限")
    public Result<List<ErpMenuBtnVO>> getRoleMenuBtnStr(Long roleId) {
        List<ErpMenuBtnVO> roleMenuVOS = roleMenuService.getRoleMenuBtnStr(roleId);
        return Result.success(roleMenuVOS);
    }
    
    @Log(operation = "角色", businessType = BusinessType.ASSIGN)
    @PostMapping("upRoleMenuStr")
    @ApiOperation("修改角色的权限按钮")
    public Result<String> upRoleMenuStr(@RequestBody Map<String, Object> data){
        int i = roleMenuService.upRoleMenuStr(data);
        return i > 0 ? Result.success("修改成功！") : Result.error("修改失败！");
    }
    
    @GetMapping("/getBtnStr")
    @ApiOperation("根据点击的菜单类型返回")
    public Result<List<String>> getBtnStr(@RequestAttribute("user") ErpUser user, Long menuId) {
        return Result.success(roleMenuService.getBtnStr(user.getId(), menuId));
    }
}
